<template>
  <div>
    <p> {{ msg }}控制台输出--- </p>
    <ul>
      <li v-for="(val,ind) in arr" :key="ind">{{val}} </li>
    </ul>
    <button @click="arr.push(2)">添加2</button>

    <hr>
    
    <!-- 组件通信  操作同一套数据 观察更新阶段 生命周期执行过程 -->
    <ul>
      <li v-for="(val, ind) in list" :key="ind">{{val}} </li>
    </ul>
    <button @click="add">添加3 </button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      msg: '子组件',
      arr:['a','b','c']
    }
  },
  props:['list'],
  methods: {
    add(){
      this.$emit('addFn', 3)
    }
  },



  beforeCreate() {
    console.log('beforeCreate----执行')
    console.log(this.msg)
  },
  created() {
    console.log('created--执行了')
    console.log(this.msg)
  },
  beforeMount() {
    console.log('beforeMount--执行')
    console.log(document.querySelector('p')) 
  },
  mounted() {
    console.log('mounted--执行')
    console.log(document.querySelector('p')) 
  },
  beforeUpdate() {
    console.log('beforeUpdate--执行')
  },
  updated() {
    console.log('Updated-- 执行')
  },
  beforeDestroy() {
    console.log('beforeDestroy---执行')
    clearInterval(this.timer)
  },
  destroyed() {
    console.log('destroyed--执行')
  }
}
</script>

<style>
</style>